package com.wwp.tbshop.presenter;

import android.util.Log;

import com.wwp.tbshop.activity.ProductDetailActivity;
import com.wwp.tbshop.model.bean.BaseBean;
import com.wwp.tbshop.model.bean.ProductDetailBean;

import retrofit2.Call;

/**
 * Created by QIANG on 2017/6/16.
 */

public class ProductDetailPresenter extends BasePresenter {

    private ProductDetailActivity mProductDetailActivity;

    public ProductDetailPresenter(ProductDetailActivity productDetailActivity) {
        mProductDetailActivity = productDetailActivity;
    }

    public void loadProductData(int pId){
        //TODO:根据点击某个商品,传入该商品的pId

        Call<ProductDetailBean> productPic = mApiService.getProductPic(pId);
        productPic.enqueue(mCallback);

    }

    @Override
    protected void onServerBug(int code) {

    }

    @Override
    protected void onConnectError(String message) {

    }

    @Override
    protected void onSuccess(BaseBean baseBean) {

        ProductDetailBean bean  = (ProductDetailBean) baseBean;

        if(bean == null){
            Log.d("detail", " 没有获取到数据 ");
            return;
        }
        ProductDetailBean.ProductBean pic = bean.getProduct();
        mProductDetailActivity.onProductSuccess(pic);
    }
}
